package com.zz.parkingsystem.service.impl;

import com.zz.parkingsystem.dto.CarDTO;
import com.zz.parkingsystem.dto.OrderDTO;
import com.zz.parkingsystem.dto.UserDTO;
import com.zz.parkingsystem.entity.User;
import com.zz.parkingsystem.mapper.AccountMapper;
import com.zz.parkingsystem.mapper.CarMapper;
import com.zz.parkingsystem.mapper.OrderItemMapper;
import com.zz.parkingsystem.mapper.UserMapper;
import com.zz.parkingsystem.service.PCUserService;
import com.zz.parkingsystem.vo.*;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class PCUserServiceImpl implements PCUserService {
    @Resource
    private UserMapper userMapper;
    @Resource
    private AccountMapper accountMapper;
    @Resource
    private CarMapper carMapper;
    @Resource
    private OrderItemMapper orderItemMapper;


    @Override
    public List<AllUserVO> getAllUserExcel(UserDTO userDto) {
        return userMapper.getAllUserExcel(userDto);
    }

    @Override
    public Long getCountOrder(OrderDTO orderDto) {
        return orderItemMapper.getCountOrder(orderDto);
    }

    @Override
    public List<OrderUserVO> getOrderMes(Long id) {
        return orderItemMapper.getOrderMes(id);
    }

    @Override
    public Long getCountCar(CarDTO carDto) {
        return carMapper.getCountCar(carDto);
    }


    @Override
    public Long getCount(UserDTO userDto) {
        return userMapper.getCount(userDto);
    }

    @Override
    public List<CarUserVO> getCarMes(Long id) {
        return carMapper.getCarMes(id);
    }

    /*
     * 用户基本信息表*/
    @Override
    public AccUserVO getUserAccMes(Long id) {
//        CarUserVO carUserVO = new CarUserVO();
//        int unpayOrder = userMapper.getUnpayOrder(id);
//        carUserVO.setUnpayOrder(unpayOrder);
        return accountMapper.getUserAccMes(id);
    }
    /*
    * 用户基本信息表*/
    @Override
    public BaseUserVO getUserBaseMes(Long id) {
        return userMapper.getUserBaseMes(id);
    }

    /*
    * 查询所有用户信息
    * */
    @Override
    public List<AllUserVO> getAllUsers(UserDTO userDto) {
        return userMapper.getAllUsers(userDto);
    }

    /*
    * 检索未支付订单总数,放到AllUserVo中
    * */
    @Override
    public int getUnpayOrder(Long orderStatus) {
        int unpayOrder = userMapper.getUnpayOrder(orderStatus);
        AllUserVO allUserVO = new AllUserVO();
        allUserVO.setUnpayOrder(unpayOrder);
        return unpayOrder;
    }

    @Override
    public String updateUserStatus(Long id) {
        User user = userMapper.selectByPrimaryKey(id);
        if(user.getUserStatus()==0){
            int i = userMapper.updateUserStatus(id);
            return "修改成功";
        }
        return "该用户已经是禁用状态";
    }

    /*
    * 更改用户状态
    * */
    @Override
    public User selectByPrimaryKey(Long id) {
        return userMapper.selectByPrimaryKey(id);
    }

}
